$(function () {

    $("#bzj_bzjlx").bzjsjzdcombobox("bzjlx");

    $("#bzj_cght_id").bzjCghtCombogrid({
        onSelect: function (rowIndex, rowData) {
            $("#bzj_hsze_lijl").val(rowData.hsze);
            $("#bzj_htms").val(rowData.htms);
            $("#bzj_ejzh_id").combobox({
                url: $.webPath() + "/organ/ejzh/findEjzhByKhId?khId=-1"
            });
            $("#bzj_kh_id").combobox({
                url: $.webPath() + '/organ/gsjg/findXyKhByHtId_qclist?htId=' + rowData.id,
                onSelect: function (row) {
                    var url = $.webPath() + "/organ/ejzh/findEjzhByKhId?nbgsId=" + $("#bzj_nbgs_id").combotree("getValue") + "&&khId=" + $("#bzj_kh_id").combobox("getValue");
                    $("#bzj_ejzh_id").combobox("reload", url);
                    var htms=$("#bzj_htms").val();
                    if(htms=='xsms'){
                        $('#bzj_sk_id').bzjSkCombogrid(row.id, $("#bzj_cght_id").combotree("getValue"),0);
                    }else{
                        $('#bzj_sk_id').bzjSkCombogrid(row.id, $("#bzj_cght_id").combotree("getValue"),1);
                    }
                }
            });
            $("#bzj_nbgs_id").combobox({
                url: $.webPath() + '/organ/gsjg/findNbgsByHtId_qclist?htId=' + rowData.id
            });
            $.ajax({
                url:$.webPath() + '/zjgl/bzj/bzjQueryByHtid?bzjId=' + rowData.id,
                data:'json',
                success: function (data) {
                    if(data !=null){
                        $("#bzj_bl").numberbox('setValue',data[0]);
                        if(opeType) {
                            $("#bzj_bl").numberbox('disable');
                        }
                    }else{
                        $("#bzj_bl").numberbox('clear');
                        $("#bzj_llje").html("");
                        $("#bzj_bl").numberbox('enable');
                    }
                }
            });
        }
    });

    var htId = $("#Bzjcght_id").val();
    var khId = $("#bzjKh_id").val();
    if (htId) {
        $("#bzj_kh_id").combobox({
            url: $.webPath() + '/organ/gsjg/findXyKhByHtId_qclist?htId=' + htId,
            onSelect: function (row) {
                var url = $.webPath() + "/organ/ejzh/findEjzhByKhId?nbgsId=" + $("#bzj_nbgs_id").combotree("getValue") + "&&khId=" + $("#bzj_kh_id").combobox("getValue");
                $("#bzj_ejzh_id").combobox("reload", url);
            }
        });

        $('#bzj_sk_id').bzjSkCombogrid(khId,htId);
        $("#bzj_nbgs_id").combobox({
            url: $.webPath() + '/organ/gsjg/findNbgsByHtId_qclist?htId=' + htId
        });
    }
//
//    if (khId) {
//        $("#bzj_ejzh_id").combobox({
//            url: $.webPath() + "/organ/ejzh/findEjzhByKhId?nbgsId=" + $("#bzj_nbgs_id").combotree("getValue") + "&&khId=" + $("#bzj_kh_id").combobox("getValue")
//        });
//
//    }

    var bzjId = $("[name='bzj.id']").val();
    if (bzjId) {
        $("#bzj_llje").html(formatJe2($("[name='bzj.llje']").val()) + "元");
        $('#bzj_sk_id').bzjSkCombogrid(khId,htId);
    } else {
       $('#bzj_sk_id').bzjSkCombogrid(0,0);
    }

//保证金比例变换改变实际金额
    $("#bzj_bl").numberbox({
        onChange: function (newValue, oldValue) {
            var hsze = $("#bzj_hsze_lijl").val();
            if (hsze) {
                var je = hsze * parseFloat(newValue) / 100;
                $("[name='bzj.llje']").val(je);
                $("#bzj_llje").html(formatJe2(je) + "元");
            }
        }
    })
});